# -*- coding: utf-8 -*-
# 引入webdriver和unittest所需要的包
import HTMLTestRunner
import re
import time
import time
import unittest

from selenium import webdriver
from selenium.common.exceptions import NoAlertPresentException
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select

from departManage.testDepartManage import testDepartManage
from home.testHome import testHome
from login.loginTest import loginTest
from mobileSet.testMobileSet import testMobileSet
from personInOutRecord.testPersonInOutRecord import testPersonInOutRecord
from personManage.testPersonManage import testPersonManage
from projectManagement.testProjectManage import testProjectManage
from roleManage.testRoleManage import testRoleManage
from sysManage.testSysManage import testSysManage
from sysMonitor.testSysMonitor import testSysMonitor
from sysNotice.testSysNotice import testSysNotice
from technicalSpecification.testTechnicalSpecification import testTechnicalSpecification
from utilities import CommonConfig
from utilities.CommonConfig import CommonConfig


# 引入HTMLTestRunner包

class Djjl(unittest.TestCase):
    # 初始化设置
    #mydrive = loginTest.login('')

    def setUp(self):
        pass
        '''driver = webdriver.Firefox()
        driver.implicitly_wait(30)
        base_url = "http://222.76.113.125:38080/fzdjjl/#/user/login?redirect=%2F"
        verificationErrors = []
        accept_next_alert = True
        return driver'''

    # 百度搜索用例
    def test_djjl(self):
        '''mydrive = webdriver.Firefox()
        mydrive.maximize_window()
        # self.driver.implicitly_wait(30)
        base_url = "http://222.76.113.125:38080/fzdjjl/#/user/login?redirect=%2F"
        mydrive.get(base_url)'''

        username = self.mydrive.find_element_by_id("username")
        username.clear()
        username.send_keys("chenfan")
        password = self.find_element_by_id("password")
        password.clear()
        password.send_keys("aa")
        submit = self.find_element_by_tag_name("button")
        submit.click()
        time.sleep(2)
       # mydrive.close()

    def tearDown(self):
        # self.driver.quit()
        #self.assertEqual([], self.verificationErrors)
        pass


if __name__ == "__main__":

    test = unittest.TestSuite()

    # time.sleep(30)
    # 将测试用例，加入到测试容器中
    # test.addTest(Djjl("test_djjl"))

    # test.addTest(testHome("test_home"))
    # time.sleep(40)
    # test.addTest(testHome("test_home_notice"))
    # time.sleep(20)
    # test.addTest(testHome("test_home_search"))
    # time.sleep(20)
    # test.addTest(testMobileSet("test_mobileSet"))
    # time.sleep(20)
    # test.addTest(testDepartManage("test_departManage"))
    # time.sleep(20)
    # test.addTest(testPersonInOutRecord("test_personInOutRecord"))

    # test.addTest(testProjectManage("test_projectManage"))
    # test.addTest(testPersonManage("test_personManage"))
    test.addTest(testRoleManage("test_roleManage"))
    test.addTest(testSysManage("test_sysManage"))
    test.addTest(testSysMonitor("test_sysMonitor"))
    test.addTest(testSysNotice("test_sysNotice"))
    test.addTest(testTechnicalSpecification("test_technicalSpecification"))
    # 定义个报告存放的路径，支持相对路径
    file_path = "D:\\testReport\\result.html"
    file_result = open(file_path, 'wb')

    # 定义测试报告
    #runner = unittest.TextTestRunner()
    runner = HTMLTestRunner.HTMLTestRunner(
        stream=file_result, title=u"代建监理测试报告", description=u"用例执行情况")

    # 运行测试用例
    runner.run(test)
    file_result.close()
